package cs5226.actions;

import java.sql.ResultSet;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionSupport;

import cs5226.dao.DebugInterfaceDAO;
import cs5226.model.SQLResultSet;

public class DebugInterfaceAction extends ActionSupport implements
		ServletRequestAware {
	private String sqlString;
	private HttpServletRequest request = null;

	@Override
	public String execute() throws Exception {
		try {
			SQLResultSet srs = DebugInterfaceDAO.execute(sqlString);
			request.setAttribute("debug-interface-execution-resultset", srs);
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("error", e.getMessage());
		}

		return super.SUCCESS;
	}

	public String getSqlString() {
		return sqlString;
	}

	public void setSqlString(String sqlString) {
		this.sqlString = sqlString;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		request = arg0;
	}
}
